package huawei.js2025;

/**
 * 最大时间
 */
public class Question5 {

    public String maxTime(int[] nums) {
        StringBuilder sb = new StringBuilder();

        // 找小时1
        find(sb, nums, 2);
        // 找小时2
        find(sb, nums, 3);
        sb.append(":");
        // 找分钟1
        find(sb, nums, 5);
        // 找分钟2
        find(sb, nums, 9);
        sb.append(":");
        // 找秒钟1
        find(sb, nums, 5);
        // 找秒钟2
        find(sb, nums, 9);

        return sb.toString();
    }

    public void find(StringBuilder sb, int[] nums, int max) {
        for (int i = max; i >= 0; i--) {
            for (int j = 0; j < nums.length; j++) {
                if (nums[j] == i) {
                    sb.append(i);
                    nums[j] = -1;
                    return;
                }
            }
        }
    }

    public static void main(String[] args) {
        int[] ints = {0, 0, 0, 0, 5, 1};

        Question5 question5 = new Question5();
        String s = question5.maxTime(ints);
        System.out.println(s);
    }
}
